home *** CD-ROM | disk | FTP | other *** search
/ Aminet 44 / Aminet 44 (2001)(GTI - Schatztruhe)[!][Aug 2001].iso / Aminet / dev / moni / systemviewer.lha / SysDevs.c < prev    next >
C/C++ Source or Header  |  2001-04-25  |  25KB  |  958 lines

  1. /****h* SystemDevices/SysDevs.c [1.1] ********************************
  2. *
  3. * NAME
  4. *    SysDevs.c
  5. *
  6. * DESCRIPTION
  7. *    Display a list of all Devices currently known to the OS.
  8. *
  9. * FUNCTIONAL INTERFACE:
  10. *
  11. *   FUNCTIONS FROM SysCommon.c:
  12. *
  13. *     PUBLIC int  SetupSystemList( (*OpenWindowFunc)( void ) );
  14. *
  15. *     PUBLIC void ShutdownSystemList( void );
  16. *
  17. *   FUNCTIONS FROM Priority.c:
  18. *
  19. *     PUBLIC int ChangePriorityHandler( char *name, int ObjType, 
  20. *                                       int frompri
  21. *                                     );
  22. **********************************************************************
  23. *
  24. */
  25.  
  26. #include <string.h>
  27.  
  28. #include <exec/execbase.h>
  29. #include <exec/types.h>
  30. #include <exec/devices.h>
  31. #include <exec/libraries.h>
  32.  
  33. #include <intuition/intuition.h>
  34. #include <intuition/classes.h>
  35. #include <intuition/classusr.h>
  36. #include <intuition/gadgetclass.h>
  37.  
  38. #include <libraries/gadtools.h>
  39.  
  40. #include <graphics/displayinfo.h>
  41. #include <graphics/gfxbase.h>
  42.  
  43. #include <clib/exec_protos.h>
  44. #include <clib/intuition_protos.h>
  45. #include <clib/gadtools_protos.h>
  46. #include <clib/graphics_protos.h>
  47. #include <clib/diskfont_protos.h>
  48.  
  49. #include "CPGM:GlobalObjects/CommonFuncs.h"
  50.  
  51. #include "SysLists.h"
  52.  
  53. #ifndef  StrBfPtr
  54. # define StrBfPtr( g ) (((struct StringInfo *)g->SpecialInfo)->Buffer)
  55. #endif
  56.  
  57. #define DLV       0
  58. #define Update    1
  59. #define Cancel    2
  60. #define RemoveBt  3
  61. #define Priority  4
  62. #define Close     5
  63. #define Flush     6
  64.  
  65. #define DEVICELISTGADGET DLRGadgets[ DLV ]
  66.  
  67. #define DLR_CNT   7
  68.  
  69. PUBLIC struct List *DevListPtr = NULL;
  70.  
  71. PRIVATE char ver[] = "\0$VER: SysDevices 1.1 (25-Apr-2001) by J.T. Steichen\0";
  72.  
  73. PRIVATE char fmt[]  = "%08LX %-8.8s %4d %5d %-8.8s %5d %5d %-29.29s";
  74.  
  75. PRIVATE struct Library *CurrentDLR = NULL;
  76.  
  77. PRIVATE struct Window       *DLRWnd   = NULL;
  78. PRIVATE struct Gadget       *DLRGList = NULL;
  79. PRIVATE struct IntuiMessage  DLRMsg;
  80. PRIVATE struct Gadget       *DLRGadgets[ DLR_CNT ];
  81. PRIVATE struct TextFont     *DLRFont  = NULL;
  82.  
  83. PRIVATE UWORD  DLRLeft   = 0;
  84. PRIVATE UWORD  DLRTop    = 16;
  85. PRIVATE UWORD  DLRWidth  = 635;
  86. PRIVATE UWORD  DLRHeight = 240;
  87. PRIVATE UBYTE *DLRWdt    = "System Device/Library/Resource Info:";
  88.  
  89. // -------------------------------------------------------------------
  90.  
  91. PRIVATE struct IntuiText DLRIText[] = {
  92.  
  93.    2, 0, JAM1, 0, 8, NULL, 
  94.    "Address: Type:       Pri: Open Version: Neg: Pos: Name:", NULL 
  95. };
  96.  
  97. #define MAXDEVS    150
  98. #define NODELENGTH 80
  99.  
  100. PRIVATE struct List DLRList;
  101. PRIVATE struct Node DLRNodes[ MAXDEVS ] = { NULL, };
  102. PRIVATE UBYTE       NodeStrs[ MAXDEVS * NODELENGTH ] = "";
  103.  
  104. PRIVATE struct ListViewMem lvm = { 0, };
  105.     
  106. // -------------------------------------------------------------------
  107.  
  108. UWORD DLRGTypes[] = {
  109.  
  110.    LISTVIEW_KIND,   BUTTON_KIND,   BUTTON_KIND,
  111.    BUTTON_KIND,     BUTTON_KIND,   BUTTON_KIND, 
  112.    BUTTON_KIND
  113. };
  114.  
  115. PRIVATE int DLVClicked(      int whichitem );
  116. PRIVATE int UpdateClicked(   int dummy     );
  117. PRIVATE int CancelClicked(   int dummy     );
  118. PRIVATE int RemoveClicked(   int dummy     );
  119. PRIVATE int PriorityClicked( int dummy     );
  120. PRIVATE int CloseClicked(    int dummy     );
  121. PRIVATE int FlushClicked(    int dummy     );
  122.  
  123. PRIVATE struct NewGadget DLRNGad[] = {
  124.  
  125.      2,  15, 625, 200,                NULL,    NULL, DLV,      0,
  126.    NULL, (APTR) DLVClicked,
  127.    
  128.      4, 216,  72,  17, (UBYTE *) "_Update",    NULL, Update,
  129.    PLACETEXT_IN, NULL, (APTR) UpdateClicked,
  130.  
  131.    554, 216,  72,  17, (UBYTE *) "_Cancel",    NULL, Cancel,
  132.    PLACETEXT_IN, NULL, (APTR) CancelClicked,
  133.  
  134.     89, 216,  72,  17, (UBYTE *) "Remove",     NULL, RemoveBt,
  135.    PLACETEXT_IN, NULL, (APTR) RemoveClicked,
  136.  
  137.    172, 216,  72,  17, (UBYTE *) "Priority",   NULL, Priority, 
  138.    PLACETEXT_IN, NULL, (APTR) PriorityClicked,
  139.    
  140.    255, 216,  72,  17, (UBYTE *) "Close",      NULL, Close,
  141.    PLACETEXT_IN, NULL, (APTR) CloseClicked,
  142.  
  143.    338, 216,  82,  17, (UBYTE *) "_Flush Sys", NULL, Flush,
  144.    PLACETEXT_IN, NULL, (APTR) FlushClicked
  145. };
  146.  
  147. PRIVATE ULONG DLRGTags[] = {
  148.  
  149.    GTLV_ShowSelected, NULL, LAYOUTA_Spacing, 2, TAG_DONE,
  150.  
  151.    GT_Underscore, '_', TAG_DONE,
  152.    GT_Underscore, '_', TAG_DONE,
  153.    GA_Disabled, TRUE,  TAG_DONE,
  154.    GA_Disabled, TRUE,  TAG_DONE,
  155.    GA_Disabled, TRUE,  TAG_DONE,
  156.    GA_Disabled, TRUE,  GT_Underscore, '_', TAG_DONE
  157. };
  158.  
  159. // -------------------------------------------------------------------
  160.  
  161. PRIVATE int InitializeDeviceList( void )
  162. {
  163.    IMPORT struct ExecBase *SysBase;
  164.  
  165.    struct Node   *ptr  = NULL;
  166.    struct Device *d    = NULL;
  167.    char v[20],   *vers = &v[0];
  168.    char t[10],   *type = &t[0];
  169.    char          *nm   = NULL;
  170.    int            i    = 0, version, rev;
  171.  
  172.    HideListFromView( DEVICELISTGADGET, DLRWnd );
  173.  
  174.    Forbid();
  175.  
  176.      DevListPtr = &SysBase->DeviceList;
  177.      ptr        = DevListPtr->lh_Head;
  178.      d          = (struct Device  *) ptr;
  179.      CurrentDLR = &(d->dd_Library);
  180.      version    = CurrentDLR->lib_Version;
  181.      rev        = CurrentDLR->lib_Revision;
  182.  
  183.      while (i < MAXDEVS && CurrentDLR != NULL)
  184.         {
  185.         nm = CurrentDLR->lib_Node.ln_Name; //lib_IdString;
  186.  
  187.         if (strlen( nm ) < 1)
  188.            goto SkipBlankDeviceName;
  189.  
  190.         if (CurrentDLR->lib_Node.ln_Type == NT_DEVICE)
  191.            strcpy( type, "device" );
  192.         else
  193.            strcpy( type, "????????" );
  194.            
  195.         sprintf( vers, "%4d.%-4d", version, rev );
  196.  
  197.         // "Address  Type    Pri  Open Version  Neg  Pos  Name"        
  198.         sprintf( &NodeStrs[ i++ * NODELENGTH ],
  199.                  &fmt[0],
  200.                  CurrentDLR, 
  201.                  type,
  202.                  CurrentDLR->lib_Node.ln_Pri,
  203.                  CurrentDLR->lib_OpenCnt,
  204.                  vers,
  205.                  CurrentDLR->lib_NegSize,
  206.                  CurrentDLR->lib_PosSize,
  207.                  (nm == NULL ? "** NO NAME **" : nm)
  208.                );
  209.  
  210. SkipBlankDeviceName:
  211.          
  212.         CurrentDLR = ((struct Library *) 
  213.                        CurrentDLR)->lib_Node.ln_Succ;
  214.  
  215.         if (CurrentDLR == NULL)
  216.            break;
  217.  
  218.         version = CurrentDLR->lib_Version;
  219.         rev     = CurrentDLR->lib_Revision;
  220.         } 
  221.  
  222.    Permit();
  223.  
  224.    Forbid();   
  225.  
  226.      if (i < MAXDEVS)
  227.         {
  228.         DevListPtr = &SysBase->ResourceList;
  229.         CurrentDLR = (struct Library *) DevListPtr->lh_Head;
  230.         version    = CurrentDLR->lib_Version;
  231.         rev        = CurrentDLR->lib_Revision;
  232.  
  233.         while (i < MAXDEVS && CurrentDLR != NULL)
  234.            {
  235.            nm = CurrentDLR->lib_Node.ln_Name; // lib_IdString;
  236.  
  237.            if (strlen( nm ) < 1)
  238.               goto SkipBlankResourceName;
  239.  
  240.            if (CurrentDLR->lib_Node.ln_Type == NT_RESOURCE)
  241.               strcpy( type, "resource" );
  242.            else
  243.               strcpy( type, "????????" );
  244.  
  245.            sprintf( vers, "%4d.%-4d", version, rev );
  246.  
  247.            // "Address  Type    Pri  Open Version  Neg  Pos  Name"        
  248.            sprintf( &NodeStrs[ i++ * NODELENGTH ], 
  249.                     &fmt[0],
  250.                     CurrentDLR, 
  251.                     type,
  252.                     CurrentDLR->lib_Node.ln_Pri,
  253.                     CurrentDLR->lib_OpenCnt,
  254.                     vers,
  255.                     CurrentDLR->lib_NegSize,
  256.                     CurrentDLR->lib_PosSize,
  257.                     (nm == NULL ? "** NO NAME **" : nm)
  258.                   );
  259.  
  260. SkipBlankResourceName:
  261.          
  262.            CurrentDLR = ((struct Library *) 
  263.                           CurrentDLR)->lib_Node.ln_Succ;
  264.       
  265.            if (CurrentDLR == NULL)
  266.               break;
  267.  
  268.            version = CurrentDLR->lib_Version;
  269.            rev     = CurrentDLR->lib_Revision;
  270.            } 
  271.         }   
  272.  
  273.    Permit();
  274.  
  275.    Forbid();
  276.  
  277.      if (i < MAXDEVS)
  278.         {
  279.         DevListPtr = &SysBase->LibList;
  280.         CurrentDLR = (struct Library *) DevListPtr->lh_Head;
  281.         version    = CurrentDLR->lib_Version;
  282.         rev        = CurrentDLR->lib_Revision;
  283.         
  284.         while (i < MAXDEVS && CurrentDLR != NULL)
  285.            {
  286.            nm = CurrentDLR->lib_Node.ln_Name;
  287.  
  288.            if (strlen( nm ) < 1)
  289.               goto SkipBlankLibName;
  290.               
  291.            if (CurrentDLR->lib_Node.ln_Type == NT_LIBRARY)
  292.               strcpy( type, "library" );
  293.            else
  294.               strcpy( type, "????????" );
  295.  
  296.            sprintf( vers, "%4d.%-4d", version, rev );
  297.  
  298.            // "Address  Type    Pri  Open Version  Neg  Pos  Name"        
  299.            sprintf( &NodeStrs[ i++ * NODELENGTH ], 
  300.                     &fmt[0],
  301.                     CurrentDLR, 
  302.                     type,
  303.                     CurrentDLR->lib_Node.ln_Pri,
  304.                     CurrentDLR->lib_OpenCnt,
  305.                     vers,
  306.                     CurrentDLR->lib_NegSize,
  307.                     CurrentDLR->lib_PosSize,
  308.                     (nm == NULL ? "** NO NAME **" : nm)
  309.                   );
  310.  
  311. SkipBlankLibName:
  312.          
  313.            CurrentDLR = ((struct Library *) 
  314.                           CurrentDLR)->lib_Node.ln_Succ;
  315.       
  316.            if (CurrentDLR == NULL)
  317.               break;
  318.  
  319.            version = CurrentDLR->lib_Version;
  320.            rev     = CurrentDLR->lib_Revision;
  321.            }
  322.         }
  323.  
  324.      // Reset CurrentDLR to the Head of the list.
  325.      DevListPtr = &SysBase->DeviceList;
  326.      CurrentDLR = (struct Library *) DevListPtr->lh_Head;
  327.  
  328.    Permit();
  329.  
  330.    ModifyListView( DEVICELISTGADGET, DLRWnd, &DLRList, NULL );
  331.  
  332.    DisplayTitle( DLRWnd, DLRWdt );
  333.  
  334.    return( i );
  335. }
  336.  
  337. // -----------------------------------------------------------------
  338.  
  339. PRIVATE void CloseDLRWindow( void )
  340. {
  341.    if (DLRWnd != NULL)
  342.       {
  343.       CloseWindow( DLRWnd );
  344.       DLRWnd = NULL;
  345.       }
  346.  
  347.    if (DLRGList != NULL)
  348.       {
  349.       FreeGadgets( DLRGList );
  350.       DLRGList = NULL;
  351.       }
  352.  
  353.    if (DLRFont != NULL)
  354.       {
  355.       CloseFont( DLRFont );
  356.       DLRFont = NULL;
  357.       }
  358.  
  359.    return;
  360. }
  361.  
  362. // -----------------------------------------------------------------
  363.  
  364. PRIVATE char wt[80] = { 0, }, *modtitle = &wt[0];
  365.  
  366.  
  367. PRIVATE int DLVClicked( int whichitem )
  368. {
  369.    ULONG addr = 0L;
  370.  
  371.    // Get address from the item:
  372.    
  373.    (void) stch_l( DLRNodes[ whichitem ].ln_Name, (long *) &addr );
  374.  
  375.    CurrentDLR = (struct Library *) addr;
  376.     
  377.    if (addr != NULL)
  378.       {
  379.       sprintf( modtitle, "%-45.45s  You Selected:  %08LX", DLRWdt, addr );
  380.  
  381.       DisplayTitle( DLRWnd, modtitle );
  382.       }
  383.  
  384.    // Enable buttons because user made a valid selection from the ListView:
  385.  
  386.    GT_SetGadgetAttrs( DLRGadgets[ RemoveBt ], DLRWnd, NULL,
  387.                       GA_Disabled, FALSE, TAG_DONE 
  388.                     );
  389.  
  390.    GT_SetGadgetAttrs( DLRGadgets[ Priority ], DLRWnd, NULL,
  391.                       GA_Disabled, FALSE, TAG_DONE 
  392.                     );
  393.    
  394.    GT_SetGadgetAttrs( DLRGadgets[ Close ], DLRWnd, NULL,
  395.                       GA_Disabled, FALSE, TAG_DONE 
  396.                     );
  397.  
  398.    GT_SetGadgetAttrs( DLRGadgets[ Flush ], DLRWnd, NULL,
  399.                       GA_Disabled, FALSE, TAG_DONE 
  400.                     );
  401.    
  402.    return( (int) TRUE );
  403. }
  404.  
  405. // -----------------------------------------------------------------
  406.  
  407. PRIVATE int UpdateClicked( int dummy )
  408. {
  409.    int i;
  410.  
  411.    DisplayTitle( DLRWnd, "Updating list..." );
  412.    
  413.    for (i = 0; i < MAXDEVS; i++)          // 0 = No ListView title.
  414.        NodeStrs[ i * NODELENGTH ] = '\0'; // Kill old ListView strings.
  415.  
  416.    if (InitializeDeviceList() <= 0)
  417.       {
  418.       // No Devices/Libraries/Resources known to SysBase!!
  419.       UserInfo( "No Device/Libraries/Resources found!", "OS ERROR??" );
  420.       }  
  421.  
  422.    GT_RefreshWindow( DLRWnd, NULL );
  423.  
  424.    DisplayTitle( DLRWnd, DLRWdt );
  425.  
  426.    return( (int) TRUE );
  427. }
  428.  
  429. // -----------------------------------------------------------------
  430.  
  431. PRIVATE int DLRCloseWindow( void )
  432. {
  433.    CloseDLRWindow();
  434.    return( (int) FALSE );
  435. }
  436.  
  437. // -----------------------------------------------------------------
  438.  
  439. PRIVATE int CancelClicked( int dummy )
  440. {
  441.    return( DLRCloseWindow() );
  442. }
  443.  
  444. // -----------------------------------------------------------------
  445.  
  446. // Flush Unused Libraries, Resources, etc., out of Memory:
  447.  
  448. PRIVATE int FlushClicked( int dummy )
  449. {
  450.    char command[32];
  451.  
  452.    strcpy( &command[0], "AVAIL FLUSH >NIL:" );
  453.    
  454.    if (System( &command[0], TAG_DONE ) < 0)
  455.       {
  456.       sprintf( ErrMsg, 
  457.                "%s couldn't be run by the System,\ncheck your path!",
  458.                &command[0]
  459.              );
  460.  
  461.       UserInfo( ErrMsg, "Invalid command path?" );
  462.  
  463.       return( (int) TRUE );
  464.       }
  465.  
  466.    (void) UpdateClicked( 0 ); // Re-make the ListView contents.
  467.  
  468.    return( (int) TRUE );
  469. }
  470.  
  471. // -----------------------------------------------------------------
  472.  
  473. PRIVATE int CloseClicked( int dummy )
  474. {
  475.    char *name = CurrentDLR->lib_Node.ln_Name;
  476.    int   type = CurrentDLR->lib_Node.ln_Type;
  477.    BOOL  ans  = 0;
  478.    
  479.    sprintf( ErrMsg, "Close will change the Open Count\n"
  480.                     "for %s, are you sure about this?",
  481.                     name
  482.           );
  483.    
  484.    ans = SanityCheck( ErrMsg );
  485.    
  486.    if (ans == FALSE)
  487.       return( TRUE ); // User came to her senses!
  488.          
  489.    switch (type)
  490.       {
  491.       case NT_LIBRARY:
  492.          if (CurrentDLR->lib_OpenCnt > 0)
  493.             CloseLibrary( CurrentDLR );
  494.          else
  495.             {
  496.             Forbid();
  497.                RemLibrary( CurrentDLR );
  498.             Permit();
  499.             }
  500.  
  501.          break;
  502.  
  503.       case NT_DEVICE:
  504.          UserInfo( "NOT Implemented for devices!", "User Information:" );
  505. /*
  506.          if (CurrentDLR->lib_OpenCnt > 0)
  507.             CloseDevice( (struct Device *) CurrentDLR );
  508.          else
  509.             {
  510.             Forbid();
  511.                RemDevice( (struct Device *) CurrentDLR );
  512.             Permit();
  513.             }         
  514. */       
  515.          break;
  516.  
  517.       case NT_RESOURCE:
  518.  
  519.          Forbid();
  520.             Remove( &(CurrentDLR->lib_Node) );
  521.          Permit();
  522.  
  523.          (void) FlushClicked( 0 );
  524.  
  525.          break;
  526. /*
  527.       case NT_DEVICE:
  528.          {
  529.          struct MsgPort        *dmport = NULL;
  530.          struct DosPacket      *reply  = NULL;
  531.          struct DevProc        *dp     = NULL;
  532.  
  533.          struct Message         msg    = { 0, };
  534.          struct StandardPacket  spack  = { 0, };
  535.          struct MsgPort         dport  = { 0, };
  536.          struct MsgPort         drport = { 0, };
  537.  
  538.          dp     = GetDeviceProc( name, dp );
  539.          dmport = dp->dvp_DevNode->dol_Task;   // Task MsgPort!
  540.          
  541.          or: 
  542.  
  543.          dmport = DeviceProc( (STRPTR) name ); // Task MsgPort!
  544.  
  545.          msg.mn_Node.ln_Name     = name;
  546.          msg.mn_ReplyPort        = &drport;
  547.  
  548.          spack.sp_Msg            = msg;
  549.  
  550.          spack.sp_Pkt.dp_Port    = &dport;
  551.          spack.sp_Pkt.dp_Status  = 0;
  552.          spack.sp_Pkt.dp_Status2 = 0;
  553.          spack.sp_Pkt.dp_Action  = ACTION_FLUSH;
  554.          
  555.          SendPkt( &spack.sp_Pkt, (dp->dvp_Port or dmport), &drport );
  556.          reply = WaitPkt();
  557.  
  558.          if (spack.sp_Pkt.dp_Status != DOSTRUE)
  559.             {
  560.             }
  561.          // error checking????
  562.  
  563.          msg.mn_Node.ln_Name     = name;
  564.          msg.mn_ReplyPort        = &drport;
  565.  
  566.          spack.sp_Msg            = msg;
  567.  
  568.          spack.sp_Pkt.dp_Port    = &dport;
  569.          spack.sp_Pkt.dp_Status  = 0;
  570.          spack.sp_Pkt.dp_Status2 = 0;
  571.          spack.sp_Pkt.dp_Action  = ACTION_DIE;
  572.  
  573.          SendPkt( &spack.sp_Pkt, (dp->dvp_Port or dmport), &drport );
  574.          reply = WaitPkt();
  575.  
  576.          if (spack.sp_Pkt.dp_Status != DOSTRUE)
  577.             {
  578.             }
  579.  
  580.          // Error checking???
  581.  
  582.          FreeDeviceProc( dp );
  583.          }
  584.          break;
  585. */
  586.       }
  587.  
  588.    (void) FlushClicked(  0 ); // Remove from system memory.
  589.    (void) UpdateClicked( 0 ); // Update the ListViewer.
  590.  
  591.    return( (int) TRUE );
  592. }
  593.  
  594. // -----------------------------------------------------------------
  595.  
  596. PRIVATE void RemoveTheDevice( struct Library *dev )
  597. {
  598. //   char *name = CurrentDLR->lib_Node.ln_Name;
  599.    int type = dev->lib_Node.ln_Type;
  600.  
  601.    switch (type)
  602.       {
  603.       case NT_LIBRARY:
  604.          while (dev->lib_OpenCnt > 0)
  605.             CloseLibrary( dev );
  606.          
  607.          Forbid();
  608.             RemLibrary( dev );
  609.          Permit();
  610.  
  611.          break;
  612.           
  613.       case NT_DEVICE:
  614. /*         
  615.          while (dev->lib_OpenCnt > 0)
  616.             CloseDevice( (struct IORequest *) dev );
  617.  
  618.          Forbid();
  619.             RemDevice( (struct Device *) dev );
  620.          Permit();         
  621. */
  622.          break;
  623.  
  624.       case NT_RESOURCE:
  625.          /*
  626.          More work is needed here!!
  627.          */
  628.          break;      
  629.       }
  630.       
  631.    (void) FlushClicked( 0 ); // Remove from system & update ListView.
  632.  
  633.    return;
  634. }
  635.  
  636. PRIVATE int RemoveClicked( int dummy )
  637. {
  638.    if (CurrentDLR != NULL)
  639.       {
  640.       if (CurrentDLR->lib_Node.ln_Type == NT_LIBRARY
  641.           || CurrentDLR->lib_Node.ln_Type == NT_DEVICE)
  642.          {
  643.          sprintf( ErrMsg, "Are you SURE you want to Remove 0x%08LX?\n"
  644.                           "The open count is %d", 
  645.                           CurrentDLR, CurrentDLR->lib_OpenCnt
  646.                 );
  647.  
  648.          if (SanityCheck( ErrMsg ) != FALSE)
  649.             {
  650.             RemoveTheDevice( CurrentDLR );
  651.  
  652.             if (InitializeDeviceList() <= 0)
  653.                {
  654.                // No Devices known to SysBase!!
  655.                UserInfo( "No Devices/Libraries/Resources found!",
  656.                          "OS ERROR??"
  657.                        );
  658.                }
  659.  
  660.             GT_RefreshWindow( DLRWnd, NULL );
  661.             }
  662.          }
  663.       else
  664.          UserInfo( "Removal of resources NOT implemented yet!",
  665.                    "User Information:"
  666.                  );
  667.       }
  668.    else
  669.       {
  670.       // No Devices selected by the user:
  671.       UserInfo( "Select a Device/Library/Resource first!", "USER ERROR:" );
  672.  
  673.       return( (int) TRUE );
  674.       }
  675.  
  676.    return( (int) TRUE );
  677. }
  678.  
  679. // -----------------------------------------------------------------
  680.  
  681. PRIVATE int PriorityClicked( int dummy )
  682. {
  683.    IMPORT int ChangePriorityHandler( char *name, int ObjType, 
  684.                                      int frompri
  685.                                    );
  686.  
  687.    char *name = CurrentDLR->lib_Node.ln_Name;
  688.    int   pri  = CurrentDLR->lib_Node.ln_Pri;
  689.    int   type = CurrentDLR->lib_Node.ln_Type;
  690.       
  691.    if (ChangePriorityHandler( name, type, pri ) < 0)
  692.       {
  693.       int ans = 0;
  694.       
  695.       ans = Handle_Problem( "Couldn't open Priority Requester!\n"
  696.                             "   (Low memory condition?)", 
  697.                             "System ERROR:", NULL
  698.                           );
  699.  
  700.       if (ans != 0) // User pressed the ABORT! button.
  701.          {
  702.          return( FALSE );
  703.          }
  704.       }
  705.  
  706.    return( (int) TRUE );
  707. }
  708.  
  709. // -----------------------------------------------------------------
  710.  
  711. PRIVATE void DLRRender( void )
  712. {
  713.    struct IntuiText it;
  714.  
  715.    ComputeFont( Scr, Font, &CFont, DLRWidth, DLRHeight );
  716.  
  717.    CopyMem( (char *) &DLRIText, (char *) &it, 
  718.             (long) sizeof( struct IntuiText )
  719.           );
  720.  
  721.    it.ITextFont = Font;
  722.  
  723.    it.LeftEdge  = 10;
  724. /*
  725.    it.LeftEdge  = CFont.OffX + ComputeX( CFont.FontX, it.LeftEdge ) 
  726.                   - (IntuiTextLength( &it ) >> 1);
  727. */
  728.    it.TopEdge   = CFont.OffY + ComputeY( CFont.FontY, it.TopEdge ) 
  729.                   - (Font->ta_YSize >> 1);
  730.  
  731.    PrintIText( DLRWnd->RPort, &it, 0, 0 );
  732.    
  733.    return;
  734. }
  735.  
  736. PRIVATE int OpenDLRWindow( void )
  737. {
  738.    struct NewGadget  ng;
  739.    struct Gadget    *g;
  740.    UWORD             lc, tc;
  741.    UWORD             wleft = DLRLeft, wtop = DLRTop, ww, wh;
  742.  
  743.    ComputeFont( Scr, Font, &CFont, DLRWidth, DLRHeight );
  744.  
  745.    ww = ComputeX( CFont.FontX, DLRWidth );
  746.    wh = ComputeY( CFont.FontY, DLRHeight );
  747.  
  748.    if ((wleft + ww + CFont.OffX + Scr->WBorRight) > Scr->Width)
  749.       wleft = Scr->Width - ww;
  750.  
  751.    if ((wtop + wh + CFont.OffY + Scr->WBorBottom) > Scr->Height)
  752.       wtop = Scr->Height - wh;
  753.  
  754.    if ((DLRFont = OpenDiskFont( Font )) == NULL)
  755.       return( -5 );
  756.  
  757.    if ((g = CreateContext( &DLRGList )) == NULL)
  758.       return( -1 );
  759.  
  760.    for (lc = 0, tc = 0; lc < DLR_CNT; lc++)
  761.       {
  762.       CopyMem( (char *) &DLRNGad[lc], (char *) &ng, 
  763.                (long) sizeof( struct NewGadget )
  764.              );
  765.  
  766.       ng.ng_VisualInfo = VisualInfo;
  767.       ng.ng_TextAttr   = Font;
  768.  
  769.       ng.ng_LeftEdge   = CFont.OffX + ComputeX( CFont.FontX,
  770.                                                 ng.ng_LeftEdge
  771.                                               );
  772.  
  773.       ng.ng_TopEdge    = CFont.OffY + ComputeY( CFont.FontY,
  774.                                                 ng.ng_TopEdge
  775.                                               );
  776.  
  777.       ng.ng_Width      = ComputeX( CFont.FontX, ng.ng_Width );
  778.       ng.ng_Height     = ComputeY( CFont.FontY, ng.ng_Height );
  779.  
  780.       DLRGadgets[lc] = g = CreateGadgetA( (ULONG) DLRGTypes[lc], 
  781.                              g, 
  782.                              &ng, 
  783.                              (struct TagItem *) & DLRGTags[tc] );
  784.  
  785.       while (DLRGTags[tc] != NULL)
  786.          tc += 2;
  787.  
  788.       tc++;
  789.  
  790.       if (g == NULL)
  791.          return( -2 );
  792.       }
  793.  
  794.    if ((DLRWnd = OpenWindowTags( NULL,
  795.  
  796.                    WA_Left,        wleft,
  797.                    WA_Top,         wtop,
  798.                    WA_Width,       ww + CFont.OffX + Scr->WBorRight,
  799.                    WA_Height,      wh + CFont.OffY + Scr->WBorBottom,
  800.  
  801.                    WA_IDCMP,       LISTVIEWIDCMP | BUTTONIDCMP 
  802.                      | IDCMP_CLOSEWINDOW | IDCMP_REFRESHWINDOW,
  803.  
  804.                    WA_Flags,       WFLG_DRAGBAR | WFLG_DEPTHGADGET 
  805.                      | WFLG_CLOSEGADGET | WFLG_SMART_REFRESH 
  806.                      | WFLG_ACTIVATE | WFLG_RMBTRAP,
  807.                    
  808.                    WA_Gadgets,     DLRGList,
  809.                    WA_Title,       DLRWdt,
  810.                    WA_ScreenTitle, &ScrTitle[0],
  811.                    TAG_DONE )
  812.       ) == NULL)
  813.       return( -4 );
  814.  
  815.    GT_RefreshWindow( DLRWnd, NULL );
  816.    
  817.    DLRRender();
  818.    
  819.    return( 0 );
  820. }
  821.  
  822. PRIVATE int DLRVanillaKey( int whichkey )
  823. {
  824.    int rval = TRUE;
  825.    
  826.    switch (whichkey)
  827.       {
  828.       case 'u':
  829.       case 'U':
  830.          rval = UpdateClicked( 0 );
  831.          break;
  832.          
  833.       case 'c':
  834.       case 'C':
  835.       case 'q':
  836.       case 'Q':
  837.          rval = CancelClicked( 0 );
  838.          break;
  839.       }
  840.  
  841.    return( rval );
  842. }
  843.  
  844. PRIVATE int HandleDLRIDCMP( void )
  845. {
  846.    struct IntuiMessage  *m;
  847.    int                 (*func)( int code );
  848.    BOOL                  running = TRUE;
  849.  
  850.    while (running == TRUE)
  851.       {
  852.       if ((m = GT_GetIMsg( DLRWnd->UserPort )) == NULL)
  853.          {
  854.          (void) Wait( 1L << DLRWnd->UserPort->mp_SigBit );
  855.          continue;
  856.          }
  857.  
  858.       CopyMem( (char *) m, (char *) &DLRMsg, 
  859.                (long) sizeof( struct IntuiMessage )
  860.              );
  861.  
  862.       GT_ReplyIMsg( m );
  863.  
  864.       switch (DLRMsg.Class)
  865.          {
  866.          case IDCMP_REFRESHWINDOW:
  867.             GT_BeginRefresh( DLRWnd );
  868.             DLRRender();
  869.             GT_EndRefresh( DLRWnd, TRUE );
  870.             break;
  871.  
  872.          case IDCMP_CLOSEWINDOW:
  873.             running = DLRCloseWindow();
  874.             break;
  875.  
  876.          case IDCMP_VANILLAKEY:
  877.             running = DLRVanillaKey( (int) DLRMsg.Code );
  878.             break;
  879.  
  880.          case IDCMP_GADGETUP:
  881.          case IDCMP_GADGETDOWN:
  882.             func = (void *) ((struct Gadget *) DLRMsg.IAddress)->UserData;
  883.             if (func != NULL)
  884.                running = func( (int) DLRMsg.Code );
  885.    
  886.             break;
  887.          }
  888.       }
  889.    
  890.    return( running );
  891. }
  892.  
  893. PUBLIC int HandleDeviceLV( void )
  894. {
  895.    int i = 0;
  896.  
  897.    // Open Libraries, Screen & Window:
  898.    if (SetupSystemList( &OpenDLRWindow ) < 0)
  899.       {
  900.       UserInfo( "Couldn't open a System ListViewer!", 
  901.                 "Allocation Problem:"
  902.               );
  903.  
  904.       return( -1 );
  905.       }
  906.  
  907.    // Disable buttons until user selects a Device from the ListView:
  908.  
  909.    GT_SetGadgetAttrs( DLRGadgets[ RemoveBt ], DLRWnd, NULL,
  910.                       GA_Disabled, TRUE, TAG_DONE 
  911.                     );
  912.  
  913.    GT_SetGadgetAttrs( DLRGadgets[ Priority ], DLRWnd, NULL,
  914.                       GA_Disabled, TRUE, TAG_DONE 
  915.                     );
  916.  
  917.    GT_SetGadgetAttrs( DLRGadgets[ Close ], DLRWnd, NULL,
  918.                       GA_Disabled, TRUE, TAG_DONE 
  919.                     );
  920.  
  921.    SetNotifyWindow( DLRWnd ); // For Handle_Problem().
  922.  
  923.    DisplayTitle( DLRWnd, "Initializing list..." );
  924.  
  925.    
  926.    lvm.lvm_NodeStrs   = &NodeStrs[0];
  927.    lvm.lvm_Nodes      = &DLRNodes[0];
  928.    lvm.lvm_NumItems   = MAXDEVS;
  929.    lvm.lvm_NodeLength = NODELENGTH;
  930.  
  931.    SetupList( &DLRList, &lvm );   
  932.    
  933.    (void) InitializeDeviceList();
  934.  
  935.    ModifyListView( DEVICELISTGADGET, DLRWnd, &DLRList, NULL );
  936.    
  937.    GT_RefreshWindow( DLRWnd, NULL );
  938.  
  939.    DisplayTitle( DLRWnd, DLRWdt );
  940.  
  941.    (void) HandleDLRIDCMP();
  942.  
  943.    // Close the Screen & Libraries:   
  944.    ShutdownSystemList();
  945.    return( 0 );
  946. }
  947.  
  948. #ifdef DEBUG
  949.  
  950. PUBLIC int main( void )
  951. {
  952.    return( HandleDeviceLV() );
  953. }
  954.  
  955. #endif
  956.  
  957. /* ----------------------- END of SysDevs.c file! ----------------- */
  958.